import actionTypes from "./actionTypes"
import service from '../../service'
export function LoadUserAction(payload){
  return{
    type:actionTypes.LOAD_USER_LIST,
    payload:payload,
  }
}
export function LoadUserActionAsync(payload){
  return dispatch=>{
    return service.loadUserList(payload).then((res)=>{
      dispatch(LoadUserAction(res.data))
    })
  }
}
export function LoadUserOneAction(payload){
  return{
    type:actionTypes.LOAD_USER_ONE_LIST,
    payload:payload,
  }
}
export function LoadUserOneActionAsync(payload){
  return dispatch=>{
    return service.userOne(payload).then((res)=>{
      dispatch(LoadUserOneAction(res.data))
    })
  }
}
export function addUserAction(payload){
  return{
    type:actionTypes.ADD_USER,
    payload:payload,
  }
}
export function addUserActionAsync(payload){
  return dispatch=>{
    return service.addUser(payload).then((res)=>{
      dispatch(addUserAction(res.data))
    })
  }
}
export function deleteUserActionAsync(payload){
  return dispatch=>{
    return service.deleteUser(payload)
  }
}
export function updateUserActionAsync(payload){
  return dispatch=>{
    return service.updateUser(payload)
  }
}
export function searchUserActionAsync(payload){
  return dispatch=>{
    return service.searchUser(payload).then((res)=>{
      dispatch(LoadUserAction(res.data))
    })
  }
}